<?php
declare(strict_types=1);

namespace App\Dao;

use App\Model\Permission;


class PermissionDao
{

    use \App\Lib\RbacTrait;

    //通过用户id找权限
    public function searchPerByWhereId($user_id)
    {
        $data = static::permissionAll($user_id);
        return static::getTree($data);
    }
    
    //通过条件搜索权限
    public function searchByWhere($where = []){
        return Permission::query()->where($where)->get()->toArray();
        
    }

    //通过条件搜索单一条权限
    public function searchByWhereFirst($where){
        return Permission::query()->where($where)->first();
        
    }

    //通过in查找权限id
    public function searchIdByIn($where){
        return Permission::query()->whereIn('parent_id',$where)->pluck('id')->toArray();
        
    }

    //通过in查找权限
    public function searchDataByIn($where){
        return Permission::query()->whereIn('id',$where)->get()->toArray();
        
    }

    //通过in删除权限
    public function delDataByIn($where){
        return Permission::query()->whereIn('id',$where)->delete();
        
    }

    //添加权限
    public function add($data)
    {
        return Permission::create($data);
    }
    //更新权限
    public function update($where,$data)
    {
        return Permission::query()->where($where)->update($data);
    }

    
}
